/**
 * Copyright (C) 2013 DaiKit.com - daikit4gxt module (admin@daikit.com)
 *
 *         Project home : http://code.daikit.com/daikit4gxt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.daikit.daikit4gxt.client.action.standard;

import com.daikit.commons.shared.bean.BaseUser;
import com.daikit.daikit4gxt.client.DkMain;
import com.daikit.daikit4gxt.client.action.BaseAction;
import com.daikit.daikit4gxt.client.log.BaseLogger;
import com.daikit.daikit4gxt.shared.bean.ConnectionData;
import com.daikit.daikit4gxt.shared.bean.ConnectionReturnData;


/**
 * The action to be called to get connected.
 * 
 * @author tcaselli
 * @version $Revision$ Last modifier: $Author$ Last commit: $Date$
 */
public class BaseConnectAction
{

	@SuppressWarnings("unused")
	private static final BaseLogger log = BaseLogger.getLog(BaseConnectAction.class);

	/**
	 * Get the connect action without chain action if connection succeeded
	 * 
	 * @param connectionData
	 *           the {@link ConnectionData}
	 * @return the connect action
	 */
	public static BaseAction<ConnectionReturnData> get(final ConnectionData connectionData)
	{
		return get(connectionData, null);
	}

	/**
	 * Get the connect action with a chain action if connection succeeded
	 * 
	 * @param connectionData
	 *           the {@link ConnectionData}
	 * @param customChainActionIfLoginSucceded
	 *           the chain action to be executed if the connection succeeded.
	 * @return the connect action
	 */
	public static BaseAction<ConnectionReturnData> get(final ConnectionData connectionData,
			final BaseAction<?> customChainActionIfLoginSucceded)
	{
		final BaseUser previousLoggedUser = DkMain.model().getPreviousUserLogged();
		final BaseAction<ConnectionReturnData> actionDoConnect = BaseSimpleConnectAction.get(connectionData, DkMain.controller()
				.getConnectionReturnProcessor());
		actionDoConnect.setLastChainAction(BaseAfterConnectAction.get(previousLoggedUser, customChainActionIfLoginSucceded));
		return actionDoConnect;
	}

}
